/*
 *  Copyright (C) 2011  Clint Priest
 *
 *  This file is part of pklib.
 *
 *  pklib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  pklib is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with pklib.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
 
var pklibContext = this;

const MouseButtons = {	Left: 0,	Middle: 1,		Right: 2,	}

/* Establishes a wrapper context that mimics what the context would be in a basic browser
		this allows some (all?) libraries that expect to be used in a browser (rather than xul) */
var BrowserContext = {}
try { BrowserContext.document = document.getElementById('content').contentDocument; } catch(e) { }

function LoadScript(path, context) {
	try {
		/* Loads the script into the SnapLinksContext object */
		Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
			.getService(Components.interfaces.mozIJSSubScriptLoader)
			.loadSubScript(path, context || pklibContext);
	} catch(e) {
		Components.utils.reportError('LoadScript: '+path+': '+e.message+' in '+e.fileName+'('+e.lineNumber+')');
	}
}

function LoadScriptInBrowserContext(path) {
	LoadScript(path, BrowserContext);
}

LoadScript('chrome://SnapGraph/content/pklib/Extensions/Object.js');
LoadScript('chrome://SnapGraph/content/pklib/Extensions/Array.js');
LoadScript('chrome://SnapGraph/content/pklib/Extensions/Element.js');
LoadScript('chrome://SnapGraph/content/pklib/Class.js');
LoadScript('chrome://SnapGraph/content/pklib/Selector.js');
LoadScript('chrome://SnapGraph/content/pklib/Debug.js');
LoadScript('chrome://SnapGraph/content/pklib/DOM.js');
LoadScript('chrome://SnapGraph/content/pklib/Data/ValueFormat.js');
LoadScript('chrome://SnapGraph/content/pklib/Data/ValueSet.js');
LoadScript('chrome://SnapGraph/content/pklib/Graphics.js');

LoadScript('chrome://SnapGraph/content/pklib/Firefox/File.js');
LoadScript('chrome://SnapGraph/content/pklib/Firefox/Utility.js');
LoadScript('chrome://SnapGraph/content/pklib/Firefox/Commands.js');
LoadScript('chrome://SnapGraph/content/pklib/Firefox/Preferences.js');

LoadScript('chrome://SnapGraph/content/pklib/UI/UserElementLasso.js');
LoadScript('chrome://SnapGraph/content/pklib/UI/ElementHighlighter.js');
LoadScript('chrome://SnapGraph/content/pklib/UI/XulPanel.js');

window.pklib = pklibContext;
